<?php

namespace app\admin\controller;

use app\BaseController;
use app\admin\model\System as SystemModel;

class System extends BaseController
{
    public function index()
    {
        if (!$this->request->auth) return show(config('status.auth'), '认证失败');
        $data = SystemModel::where('id', 1)->find()->toArray();
        return show(200, '修改成功', $data);
    }

    public function modify()
    {
        if (!$this->request->auth) return show(config('status.auth'), '认证失败');
        $login_bg = input('login_bg', '');
        $web_color = input('web_color', '');
        $banner1 = input('banner1', '');
        $banner2 = input('banner2', '');
        $banner3 = input('banner3', '');
        $article = input('article', 0, 'intval');
        $iphone = input('iphone', 0, 'intval');
        $question = input('question', '');
        $result = SystemModel::update([
            'id' => 1,
            'login_bg' => $login_bg,
            'web_color' => $web_color,
            'banner1' => $banner1,
            'banner2' => $banner2,
            'banner3' => $banner3,
            'article' => $article,
            'iphone' => $iphone,
            'question' => $question
        ]);
        if ($result) {
            return show(200, '修改成功');
        } else {
            return show(config('status.error_update'), '修改失败');
        }
    }
}
